From 576a882bc5c9c70cfa2374b89db35ccd73300547 Mon Sep 17 00:00:00 2001 From: "kfraser@localhost.localdomain" Date: Wed, 20 Dec 2006 11:21:04 +0000 Subject: [PATCH] [LINUX] dma: Use swiotlb mask for coherent mappings too The recent change to use a default DMA bit width of 30 bits (required by chips like the b44) only converted the streaming DMA primitives. The coherent mappings are still hard-coded to 31 bits. This means that b44 still doesn't work under Xen. This patch makes the io_tlb_dma_bits variable global and uses it for coherent memory mappings. Thanks to Calvin Webster for providing a machine with a b44 and 2G of memory I've been able to verify that this finally makes the b44 work under Xen. Signed-off-by: Herbert Xu Rename 'io_tlb_dma_bits' to the more correct 'dma_bits'. This also affects the name of the boot parameter, which is now 'dma_bits='. Signed-off-by: Keir Fraser --- .../arch/i386/kernel/pci-dma-xen.c | 5 +++-- .../arch/i386/kernel/swiotlb.c | 18 +++++++++--------- .../include/asm-i386/mach-xen/asm/swiotlb.h | 2 ++ 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/linux-2.6-xen-sparse/arch/i386/kernel/pci-dma-xen.c b/linux-2.6-xen-sparse/arch/i386/kernel/pci-dma-xen.c index 5c32dd0c39..7f0538c606 100644 --- a/linux-2.6-xen-sparse/arch/i386/kernel/pci-dma-xen.c +++ b/linux-2.6-xen-sparse/arch/i386/kernel/pci-dma-xen.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -183,8 +184,8 @@ void *dma_alloc_coherent(struct device *dev, size_t size, ret = (void *)vstart; if (ret != NULL) { - /* NB. Hardcode 31 address bits for now: aacraid limitation. */ - if (xen_create_contiguous_region(vstart, order, 31) != 0) { + if (xen_create_contiguous_region(vstart, order, + dma_bits) != 0) { free_pages(vstart, order); return NULL; } diff --git a/linux-2.6-xen-sparse/arch/i386/kernel/swiotlb.c b/linux-2.6-xen-sparse/arch/i386/kernel/swiotlb.c index 4fa98132f4..ac2c0da536 100644 --- a/linux-2.6-xen-sparse/arch/i386/kernel/swiotlb.c +++ b/linux-2.6-xen-sparse/arch/i386/kernel/swiotlb.c @@ -47,8 +47,8 @@ EXPORT_SYMBOL(swiotlb); */ #define IO_TLB_SHIFT 11 -/* Width of DMA addresses in the IO TLB. 30 bits is a b44 limitation. */ -#define DEFAULT_IO_TLB_DMA_BITS 30 +/* Width of DMA addresses. 30 bits is a b44 limitation. */ +#define DEFAULT_DMA_BITS 30 static int swiotlb_force; static char *iotlb_virt_start; @@ -98,14 +98,14 @@ static struct phys_addr { */ static DEFINE_SPINLOCK(io_tlb_lock); -static unsigned int io_tlb_dma_bits = DEFAULT_IO_TLB_DMA_BITS; +unsigned int dma_bits = DEFAULT_DMA_BITS; static int __init -setup_io_tlb_bits(char *str) +setup_dma_bits(char *str) { - io_tlb_dma_bits = simple_strtoul(str, NULL, 0); + dma_bits = simple_strtoul(str, NULL, 0); return 0; } -__setup("swiotlb_bits=", setup_io_tlb_bits); +__setup("dma_bits=", setup_dma_bits); static int __init setup_io_tlb_npages(char *str) @@ -167,7 +167,7 @@ swiotlb_init_with_default_size (size_t default_size) int rc = xen_create_contiguous_region( (unsigned long)iotlb_virt_start + (i << IO_TLB_SHIFT), get_order(IO_TLB_SEGSIZE << IO_TLB_SHIFT), - io_tlb_dma_bits); + dma_bits); BUG_ON(rc); } @@ -197,7 +197,7 @@ swiotlb_init_with_default_size (size_t default_size) bytes >> 20, (unsigned long)iotlb_virt_start, (unsigned long)iotlb_virt_start + bytes, - io_tlb_dma_bits); + dma_bits); } void @@ -665,7 +665,7 @@ swiotlb_dma_mapping_error(dma_addr_t dma_addr) int swiotlb_dma_supported (struct device *hwdev, u64 mask) { - return (mask >= ((1UL << io_tlb_dma_bits) - 1)); + return (mask >= ((1UL << dma_bits) - 1)); } EXPORT_SYMBOL(swiotlb_init); diff --git a/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/swiotlb.h b/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/swiotlb.h index 74a0c21bbe..bb3d7d2416 100644 --- a/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/swiotlb.h +++ b/linux-2.6-xen-sparse/include/asm-i386/mach-xen/asm/swiotlb.h @@ -34,6 +34,8 @@ extern void swiotlb_unmap_page(struct device *hwdev, dma_addr_t dma_address, extern int swiotlb_dma_supported(struct device *hwdev, u64 mask); extern void swiotlb_init(void); +extern unsigned int dma_bits; + #ifdef CONFIG_SWIOTLB extern int swiotlb; #else -- 2.30.2